#!/bin/bash

# 测试遍历日期

param="20231010~20231105"
arr=(`echo $param | sed -e 's/~/ /g'`)
echo "start: ${arr[0]}"
echo "end: ${arr[1]}"

if [[ "$param" =~ ^[0-9]{8}~[0-9]{8}$ ]]; then
  echo "match"

  arr=(`echo $param | sed -e 's/~/ /g'`)
  start_date=${arr[0]}
  end_date=${arr[1]}

  # start_date_epoch=$(date --date "$start_date" +%s)
  # end_date_epoch=$(date --date "$end_date" +%s)  
  # for (( sec=0; sec <= end_date_epoch - start_date_epoch; sec+=86400 )); do
  #   echo "$(date --date "$start_date + $sec seconds" +"%Y%m%d")"
  # done

  until [[ $start_date > $end_date ]]; do 
      echo "loop: $start_date"
      start_date=$(date +"%Y%m%d" -d "$start_date + 1 day")
  done

fi



